package org.budo.redis.jdbc.driver.statement.mysql;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import org.budo.jdbc.driver.AbstractBudoJdbcPreparedStatement;
import org.budo.jdbc.driver.resultset.impl.MapArrayResultSet;
import org.budo.redis.jdbc.driver.statement.AbstractRedisStatement;
import org.budo.support.lang.util.MapUtil;

/**
 * 展示支持的函数列表 SHOW function status
 * 
 * @author lmw
 */
public class SHOW_FUNCTION_STATUS extends AbstractRedisStatement {
    private static final String[][] FUNCTIONS = { //
            { "TYPE", "show type of a key" }, //
            { "KEYS", "show keys" }, // , //
            { "GET", "get value of string type by key" }, //
            { "EVAL", "run a Lua script" } };

    @Override
    public void execute(PreparedStatement preparedStatement) throws SQLException{
        String[] columnNames = new String[] { "Name", "Comment", "Security_type", "Definer", "Created", "Modified" };
        Map[] mapArray = new Map[FUNCTIONS.length];
        for (int i = 0; i < FUNCTIONS.length; i++) {
            mapArray[i] = MapUtil.stringMap("Name", FUNCTIONS[i][0], //
                    "Comment", FUNCTIONS[i][1], //
                    "Security_type", "INVOKER", //
                    "Definer", "budo", //
                    "Created", "2099-09-09 09:09:09", //
                    "Modified", "2099-09-09 09:09:09");
        }

        ResultSet resultSet = new MapArrayResultSet(columnNames, mapArray);
        ((AbstractBudoJdbcPreparedStatement) preparedStatement).setResultSet(resultSet);
    }
}
